package ratons.racleurs.main;


import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.OverlayItem;

import data.POI;
import data.Parcours;

// ItemizedOverlay est la classe qui permet de définir les points de la carte
public class ItemizedOverlay extends com.google.android.maps.ItemizedOverlay 
{	
	private Context context;
	private ArrayList<OverlayItem>  arrayListOverlayItem = new ArrayList<OverlayItem>();
	private int selected_id;
	private OverlayItem item;
	
	public ItemizedOverlay(Drawable defaultMarker, Context pContext) 
	{
		super(boundCenterBottom(defaultMarker));
		this.context = pContext;
	}

	@Override
	protected OverlayItem createItem(int i) 
	{
		return arrayListOverlayItem.get(i);
	}

	@Override
	public int size() 
	{
		return arrayListOverlayItem.size();
	}
	
	 public void addOverlayItem(OverlayItem overlay)
	 {
		 arrayListOverlayItem.add(overlay);
		 populate();
	 }
	 
	 @Override
	 protected boolean onTap(int index)
	 {
		int i = 0;
		item = arrayListOverlayItem.get(index);
		System.out.println("Test : " + item.getSnippet());
		POI infos = null;
		Parcours tmp = ParcoursActivity.parcour_selectionne;
		for (POI t : tmp.getListe_poi())
		{
			if (t.getNom().compareTo(item.getSnippet())==0)
			{
				infos = t;
				i++;
			}
		}
		
		Intent intent = new Intent(context, QuestionActivity.class);
		Bundle info = new Bundle();
		ArrayList<String> arrayList = new ArrayList<String>();
		arrayList.add(item.getSnippet());
		arrayList.add(infos.getQuestion());
		arrayList.add(infos.getReponse_ok());
		arrayList.add(infos.getReponse_1());
		arrayList.add(infos.getReponse_2());
		
		
		
		System.out.println("Test test : " + arrayList.toString());
		info.putStringArrayList("poi", arrayList);
		info.putString("etape", String.valueOf(i));
		intent.putExtras(info);
 		context.startActivity(intent);
		 return true;
	}
}
